package com.ddlaw.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

public class ReadProperties <T> {
	/**
	 * 读取配置文件所有值
	 * param filePath
	 * 						文件路径
	 * param c
	 * 						读取类
	 * return
	 */
	 public Map<String,String> readValue(String filePath,Class<T> c) {
		 Map<String,String> result = new HashMap<String, String>();
		 Properties props = new Properties();
		        try {
		        	props.load(c.getClassLoader().getResourceAsStream(filePath));
		        	 Iterator<String> it=props.stringPropertyNames().iterator();
		        	         while(it.hasNext()){
		        	               String keys=it.next();
		        	               result.put(keys, props.getProperty(keys));
		        	              
		        	           }
		       
		            return result;
		        } catch (Exception e) {
		         e.printStackTrace();
		         return null;
		        }
		 }
	 /**
	  * 根据key值读取内容
	  * param filePath
	  * 						文件路径
	  * param key
	  * 						文件KEY值
	  * param c
	  * 						读取类
	  * return
	  */
	 public String readValueById(String filePath,String key,Class<T> c) {
		  Properties props = new Properties();
		        try {
		        	props.load(c.getClassLoader().getResourceAsStream(filePath));
		        	String value = props.getProperty (key);
		        	return value;
		        } catch (Exception e) {
		         e.printStackTrace();
		         return null;
		        }
		 }	
}

